import fly from "../main"


export function getOpenId($params) {
  return fly.get('https://api.weixin.qq.com/sns/jscode2session?appid=wxf9a040f8c7faaa66&secret=eb049dca1fd9db8617e07c5e56ce5956&js_code='+$params+'&grant_type=authorization_code ')
}



let modal = 'order'

/**
 * 获取接单地址列表
 * @returns {Promise<{}>}
 */
export async function getOrderList($status) {
  let response = {}
  await fly.get(`/v3/${modal}`,{status:$status}).then((res) => {
    response = res.data
  })
  return response;
}


/**
 * 添加接单地址信息
 * @param data 接单地址数据
 * @returns {Promise<{}>}
 */
export async function addOrder(data) {
  let body = {
    province_id:data[0].code,
    city_id:data[1].code,
    province_name:data[0].name,
    city_name:data[1].name,
  }
  let response = {}
  await fly.post(`/v3/${modal}`, body).then((res) => {
    response = res.data
  })
  return response;
}


/**
 * 删除接单地址信息
 * @param $id 接单地址id
 * @returns {Promise<{}>}
 */
export async function delOrder($id) {
  let response = {}
  await fly.delete(`/v3/${modal}/${$id}`).then((res) => {
    response = res.data
  })
  return response;
}


/**
 * 获取接单地址信息
 * @param $id 接单地址id
 * @returns {Promise<{}>}
 */
export async function getOrder($id) {
  let response = {}
  await fly.get(`/v3/${modal}/${$id}`).then((res) => {
    response = res.data
  })
  return response;
}

/**
 * 更新接单地址信息
 * @param id
 * @param $data
 * @returns {Promise<{}>}
 */
export async function updateOrder(id, $data) {
  let response = {}
  await fly.put(`/v3/${modal}/${id}`, $data).then((res) => {
    response = res.data
  })
  return response;
}

